package com.example.demo.testannotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2024-01-25
 * Time: 16:42
 */
@Aspect
@Component
public class CustomLogAspect {
    // 环绕通知
    @Around("@annotation(customLog)")
    public Object doAround(ProceedingJoinPoint joinPoint,CustomLogAnnotation customLog) throws Throwable {
        if (customLog.enable()) {
            System.out.println(joinPoint.getSignature().getName()+" :⽅法开始执⾏");
            long start = System.currentTimeMillis();
            // 执行目标方法
            Object obj = joinPoint.proceed();
            long end = System.currentTimeMillis();
            System.out.println(joinPoint.getSignature().getName()+" :⽅法结束执⾏，总用时："+(end-start)+"ms.");
            System.out.println(customLog.value());
            return obj;
        } else {
            return joinPoint.proceed();
        }

    }
}
